{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "9a28cee1",
   "metadata": {},
   "source": [
    "## Part I:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "id": "9c4fc879",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.datasets import load_digits\n",
    "import matplotlib.pyplot as plt "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "id": "50ebb79b",
   "metadata": {},
   "outputs": [],
   "source": [
    "digits = load_digits()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "id": "c35d7c98",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<Figure size 432x288 with 0 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPoAAAECCAYAAADXWsr9AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAAL1UlEQVR4nO3df6hX9R3H8ddrptVS0laL0MiMIUSw/IEsitg0w1a4f5YoFCw29I8tkg3K9s/ov/6K9scIxGpBZqQljNhaSkYMtprXbJnaKDFSKgsNsz+U7L0/vsdhznXPvZ3P537v9/18wBe/997vPe/3vdfX95zz/Z5z3o4IARhs3xrrBgCUR9CBBAg6kABBBxIg6EACBB1IoC+CbnuJ7bdtv2N7TeFaj9k+ZHtXyTqn1bvc9jbbu22/ZfuewvXOs/2a7Teaeg+UrNfUnGD7ddvPl67V1Ntv+03bO21vL1xrqu1Ntvfa3mP7uoK1Zjc/06nbUdurO1l4RIzpTdIESe9KmiVpkqQ3JF1dsN6NkuZK2lXp57tM0tzm/hRJ/y7881nS5Ob+REmvSvpB4Z/x15KekvR8pd/pfkkXV6r1hKRfNPcnSZpaqe4ESR9KuqKL5fXDGn2BpHciYl9EnJD0tKSflCoWEa9IOlxq+Wep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RCMAymkd9Oaa7kslbfw/X2f2GtCn2g5wkKRbJO2IiI/O9sWIWCtprTT4p6kC481INt1XiM12YFxqFfRmTPJiSc+VbQdACW1HMn0u6TuFewFQCEfGAQkQdCABgg4kQNCBBAg6kABBBxIg6EACBB1IgKADCZSavfaxpNGcs36xpE86bqcfalGPerXqXRERl5z5ySJBHy3b2yNi/qDVoh71xroem+5AAgQdSKDfgr52QGtRj3pjWq+v9tEBlNFva3QABRB0IAGCDiRA0IEECDqQwH8An6mM7XzL9vMAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 288x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.gray()\n",
    "plt.matshow(digits.images[0])\n",
    "plt.show() "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "id": "1f0aced1",
   "metadata": {},
   "outputs": [],
   "source": [
    "X = digits.data\n",
    "y = digits.target"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "id": "0e80b4c6",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.preprocessing import StandardScaler"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 126,
   "id": "0e9bb53b",
   "metadata": {},
   "outputs": [],
   "source": [
    "scaler = StandardScaler()\n",
    "X = scaler.fit_transform(X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "id": "2c6bb209",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.model_selection import train_test_split"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 128,
   "id": "77cad8a6",
   "metadata": {},
   "outputs": [],
   "source": [
    "x_train, x_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=44)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 129,
   "id": "cc86c339",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.neural_network import MLPClassifier"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "id": "221e00a2",
   "metadata": {},
   "outputs": [],
   "source": [
    "clf = MLPClassifier(max_iter=2000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 131,
   "id": "79289294",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "MLPClassifier(max_iter=2000)"
      ]
     },
     "execution_count": 131,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "clf.fit(x_train, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "id": "e15202fb",
   "metadata": {},
   "outputs": [],
   "source": [
    "y_pred = clf.predict(x_test)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 133,
   "id": "9eb92941",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.metrics import accuracy_score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 134,
   "id": "336ae239",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9944444444444445"
      ]
     },
     "execution_count": 134,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "accuracy_score(y_test, y_pred)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 135,
   "id": "a4225ba0",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.metrics import confusion_matrix"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 136,
   "id": "b7bc9515",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[45,  0,  0,  0,  0,  0,  0,  0,  0,  0],\n",
       "       [ 0, 39,  0,  0,  0,  0,  0,  0,  1,  0],\n",
       "       [ 0,  0, 34,  0,  0,  0,  0,  0,  0,  0],\n",
       "       [ 0,  0,  0, 35,  0,  0,  0,  0,  0,  0],\n",
       "       [ 0,  0,  0,  0, 29,  0,  0,  0,  0,  0],\n",
       "       [ 0,  0,  0,  0,  0, 44,  0,  0,  0,  0],\n",
       "       [ 0,  0,  0,  0,  0,  0, 37,  0,  0,  0],\n",
       "       [ 0,  0,  0,  0,  0,  0,  0, 33,  0,  0],\n",
       "       [ 0,  0,  0,  0,  0,  0,  0,  1, 27,  0],\n",
       "       [ 0,  0,  0,  0,  0,  0,  0,  0,  0, 35]], dtype=int64)"
      ]
     },
     "execution_count": 136,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "confusion_matrix(y_test, y_pred)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a987addf",
   "metadata": {},
   "source": [
    "## Part II:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 137,
   "id": "db37e1d4",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.decomposition import PCA"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 138,
   "id": "c304c102",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1.91421366e+00, -9.54501571e-01, -3.94603482e+00, ...,\n",
       "         0.00000000e+00, -0.00000000e+00,  8.24385469e-15],\n",
       "       [ 5.88980330e-01,  9.24635800e-01,  3.92475494e+00, ...,\n",
       "         7.20734713e-16,  1.90723917e-16,  3.08670512e-17],\n",
       "       [ 1.30203906e+00, -3.17188827e-01,  3.02333293e+00, ...,\n",
       "         3.36143000e-16,  1.21053089e-16,  2.15555254e-17],\n",
       "       ...,\n",
       "       [ 1.02259599e+00, -1.47910870e-01,  2.46997365e+00, ...,\n",
       "        -1.15610285e-16,  1.34951703e-17,  1.79387514e-17],\n",
       "       [ 1.07605522e+00, -3.80906254e-01, -2.45548693e+00, ...,\n",
       "        -1.40677542e-17,  2.03885647e-17, -2.28690666e-17],\n",
       "       [-1.25770233e+00, -2.22759088e+00,  2.83627891e-01, ...,\n",
       "        -3.76409513e-17, -2.23664689e-17,  5.00149356e-17]])"
      ]
     },
     "execution_count": 138,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pca = PCA()\n",
    "pca.fit_transform(X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 139,
   "id": "46ee1ba8",
   "metadata": {},
   "outputs": [
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9L1JHO9fDYiFkoaDtwtaUqUH3G5JVBuMrf/QzKadGtgODBd0t/S17YGPgS8CjwD/CoidlSycM83gWPT/caQzKuzKTBN0mbAN0jmKPuIpM1JZuXsroraJv03WQo8Iemc9NhPA/aMiMWSTgKOB85M3/NyRGwn6evAiRHxFUnnA29ExI/KHJu1IScCawaDlEz1DMkdwYUk1RP3lkkCpK/NA0jfOwZ4HXghIqYDRDrbaXqzUOiPEfEm8KakaSQn3OuB/6dkdssVJFMzr08yRXBP7QpcGRHvkEwudhuwA7AQmB7p9MOSngZuSt8zi+Quo9tvI2IF8A9Jz5DMerorcE56bI9Lmg10J4KbI+L19HMfBUYD65AsxHRH+m+wBnBXwXd0TwQ4kyR5WYdyIrBm8GYkUz2/Kz1xLa7wnqUFz9+hZ7/l4qv8AMYDI4DtI2KZkhk7B1b4jEdYOXFbTxTGvaJgewWrHkOpGLN+bve/h4C/RMSBVd7T038/azNuI7B28gSwgaQdANL2gVInuP3S+vZhJI2j00lWknopTQK7k1xRV3ILsKZWLpaCpK3SevXbgQOULGozAvg4ySRvPbG/pH5pu8Em6bHdTpKwSKuERqXl5dxNUmW2WfqetTL0aloEDOlhrNbinAisbUTE28ABwDmSHiRZUazUVf1DJFMx3w18NyKeByYDXZJmAV8GHq/yXQF8FthTSffRR4DvkVQlXZt+x4MkCePbkUxH3BNzSJLHn4EjI+It4BdAvzTG3wCHRMTSch8QEfOBQ4ArJT1EUi1UbWGdPwGfdWNxZ/Hso9ZRJJ1BkzeGSrqEZMroqxsdi3UG3xGYmXU43xGYmXU43xGYmXU4JwIzsw7nRGBm1uGcCMzMOpwTgZlZh/v/Wopnni9dH2EAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "import numpy as np\n",
    "import matplotlib\n",
    "import matplotlib.pyplot as plt\n",
    "\n",
    "plt.plot(np.cumsum(pca.explained_variance_ratio_), 'ro-', linewidth=1)\n",
    "plt.title('Scree Plot')\n",
    "plt.xlabel('Principal Component')\n",
    "plt.ylabel('Cumsum Proportion of Variance Explained')\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 140,
   "id": "38c876c4",
   "metadata": {},
   "outputs": [],
   "source": [
    "pca_empirical = PCA(n_components=15)\n",
    "pca_x = pca_empirical.fit_transform(X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 141,
   "id": "97f504c4",
   "metadata": {},
   "outputs": [],
   "source": [
    "x_train_pca, x_test_pca, y_train_pca, y_test_pca = train_test_split(pca_x, y, test_size=0.2, random_state=44)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4ed7d3be",
   "metadata": {},
   "outputs": [],
   "source": [
    "clf_pca = MLPClassifier(max_iter=2000)\n",
    "clf_pca.fit(x_train_pca, y_train_pca)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a287f24b",
   "metadata": {},
   "outputs": [],
   "source": [
    "y_pred_pca = clf_pca.predict(x_test_pca)\n",
    "accuracy_score(y_test_pca, y_pred_pca)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "66246cf7",
   "metadata": {},
   "outputs": [],
   "source": [
    "confusion_matrix(y_test_pca, y_pred_pca)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "03987997",
   "metadata": {},
   "source": [
    "## Part III:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c5cb1d0b",
   "metadata": {},
   "outputs": [],
   "source": [
    "from scipy.linalg import svd\n",
    "from numpy import diag\n",
    "X = X.T\n",
    "U, S, VT = svd(X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3358734e",
   "metadata": {},
   "outputs": [],
   "source": [
    "np.diag(S)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "168981fe",
   "metadata": {},
   "outputs": [],
   "source": [
    "sigma = np.zeros((X.shape[0], X.shape[1]))\n",
    "sigma[:X.shape[0],:X.shape[0]] = np.diag(S)\n",
    "Xc = np.dot(U, np.dot(sigma,VT))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "54eeb53e",
   "metadata": {},
   "outputs": [],
   "source": [
    "print(np.allclose(X,Xc))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "3f9af082",
   "metadata": {},
   "outputs": [],
   "source": [
    "Ur = -U[:,0:15]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "36e75211",
   "metadata": {},
   "outputs": [],
   "source": [
    "Xr = np.dot(X.T, Ur)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "011c9812",
   "metadata": {},
   "outputs": [],
   "source": [
    "x_train_svd, x_test_svd, y_train_svd, y_test_svd = train_test_split(Xr, y, test_size=0.2, random_state=44)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c85ba3f1",
   "metadata": {},
   "outputs": [],
   "source": [
    "clf_pca = MLPClassifier(max_iter=2000)\n",
    "clf_pca.fit(x_train_svd, y_train_svd)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "508daf16",
   "metadata": {},
   "outputs": [],
   "source": [
    "y_pred_svd = clf_pca.predict(x_test_svd)\n",
    "accuracy_score(y_test_svd, y_pred_svd)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "97428c98",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
